<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Duck Hunt Game QR Code</title>
    <script src="https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js"></script>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            margin: 0;
            background-color: #87CEEB;
            font-family: Arial, sans-serif;
        }
        .container {
            text-align: center;
            background: rgba(255, 255, 255, 0.9);
            padding: 2rem;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 1rem;
        }
        p {
            color: #666;
            margin-bottom: 2rem;
        }
        #qrcode {
            margin-bottom: 1rem;
        }
        .note {
            font-size: 0.9rem;
            color: #888;
            margin-top: 1rem;
        }
        #ipAddress {
            margin-top: 1rem;
            padding: 10px;
            background: #f0f0f0;
            border-radius: 5px;
            font-family: monospace;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>🦆 Duck Hunt Game</h1>
        <p>扫描二维码开始游戏</p>
        <div id="qrcode"></div>
        <div id="ipAddress"></div>
        <p class="note">提示：建议使用横屏模式游玩</p>
        <p class="note">如果扫码无法访问，请尝试直接在手机浏览器输入上方地址</p>
    </div>

    <script>
        // 获取本机IP地址并生成完整的游戏URL
        async function getLocalIPs() {
            try {
                const response = await fetch('http://ip-api.com/json/');
                const data = await response.json();
                return `http://${data.query}:8080/duck_hunting_game.html`;
            } catch (error) {
                // 如果获取失败，使用localhost
                return 'http://localhost:8080/duck_hunting_game.html';
            }
        }

        async function init() {
            const gameUrl = await getLocalIPs();
            document.getElementById('ipAddress').textContent = gameUrl;

            // 生成二维码
            const qr = qrcode(0, 'L');
            qr.addData(gameUrl);
            qr.make();
            document.getElementById('qrcode').innerHTML = qr.createImgTag(8);
        }

        init();
    </script>
</body>
</html> 